const sortTestCase = [
    [5, 2, 3, 1],
    [5, 1, 1, 2, 0, 0],
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
    [3, 1, 4, 1, 5, 9, 2, 6, 5, 3],
    [-5, -3, -2, -1, 0, 1, 2, 3, 4, 5],
    [1, 2, 3, 4, 5, 6, 8, 7, 9, 10],
    [42],
    [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
    [],
    [45, 23, 76, 52, 12, 87, 34, 99, 11, 67, 48, 90, 3, 59, 71, 26, 83, 5, 64, 14],
    [63, 95, 21, 75, 38, 47, 82, 10, 54, 69, 79, 81, 16, 32, 58, 49, 60, 36, 72, 24],
    [84, 53, 7, 39, 22, 65, 41, 97, 5, 29, 78, 36, 87, 13, 48, 74, 20, 59, 6, 91, 12],
    [68, 35, 57, 44, 1, 25, 94, 71, 86, 30, 77, 60, 17, 46, 33, 73, 90, 26, 81, 64],
    [39, 90, 84, 73, 57, 28, 41, 65, 93, 11, 26, 77, 53, 36, 82, 14, 68, 30, 48, 1],
    [87, 74, 91, 59, 38, 64, 29, 46, 7, 25, 60, 13, 42, 81, 17, 33, 5, 94, 20, 4],
    [9, 43, 52, 11, 69, 80, 16, 32, 24, 76, 18, 82, 58, 47, 21, 95, 63, 1, 35, 10],
    [19, 40, 93, 62, 83, 56, 31, 45, 88, 66, 92, 28, 50, 14, 8, 23, 70, 54, 75, 3],
    [51, 15, 98, 49, 61, 37, 79, 96, 85, 42, 2, 67, 72, 10, 55, 27, 4, 99, 89, 34],
]

function isArraySorted(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        if ((arr[i] > arr[i + 1] && !isSortedInDesc(arr))){
            return false;
        }
    }
    return true;
}

function isSortedInDesc(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] < arr[i + 1]) {
            return false;
        }
    }
    return true;
}

const checkSortFunction = (func) => {
    for (let i = 0; i < sortTestCase.length; i++) {
        const res = func(sortTestCase[i]);
        if (!isArraySorted(res)) {
            console.log(`${func.name} 未通过用例： ${sortTestCase[i]}`)
            console.log(res);
            return;
        }
    };
    console.log(`${func.name} 测试通过`)
    return true;
} 

export {
    sortTestCase,
    isArraySorted,
    checkSortFunction,
}